package com.pccc.batch.config.remotepartition.handler;

import javax.sql.DataSource;

import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.integration.partition.RemotePartitioningManagerStepBuilder;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.transaction.PlatformTransactionManager;

public class PollerRemotePartitioningManagerStepBuilderFactory implements BeanFactoryAware {

	private BeanFactory beanFactory;
	final private JobExplorer jobExplorer;
	final private JobRepository jobRepository;
	final private PlatformTransactionManager transactionManager;
	private final DataSource dataSource;
	
	public PollerRemotePartitioningManagerStepBuilderFactory(JobExplorer jobExplorer,JobRepository jobRepository,
			PlatformTransactionManager transactionManager,DataSource dataSource) {
		this.jobExplorer = jobExplorer;
		this.jobRepository = jobRepository;
		this.transactionManager = transactionManager;
		this.dataSource = dataSource;
	}
	
	
	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}
	
	
	public PollerRemotePartitioningManagerStepBuilder get(String name) {
		return new PollerRemotePartitioningManagerStepBuilder(name)
				.repository(this.jobRepository)
				.jobExplorer(this.jobExplorer)
				.beanFactory(this.beanFactory)
				.dataSource(dataSource)
				.transactionManager(this.transactionManager);
	}
}
